local dianhu = fk.CreateSkill{
    name = "heg__dianhu",
    tags = { Skill.Compulsory },
}

Fk:loadTranslationTable{
  ["heg__dianhu"] = "点虎",
  [":heg__dianhu"] = "锁定技，当你首次明置此武将时，你指定一名其他角色；当与你势力相同的角色对该角色造成伤害后，其摸一张牌。",
  ["@@heg__dianhu"] = "点虎",
  ["#heg__dianhu-choose"] = "点虎：指定一名角色，本局当你对其造成伤害或其回复体力后，你摸一张牌",

  ["$heg__dianhu1"] = "预则立，不预则废！",
  ["$heg__dianhu2"] = "就用你，给我军祭旗！",
}

local H = require "packages.ol_hegemony.util"

dianhu:addEffect(fk.GeneralRevealed,{
    mute = true,
    can_trigger = function(self, event, target, player, data)
      if player:usedSkillTimes(dianhu.name, Player.HistoryGame) == 0 and player:hasSkill(dianhu.name, true) then
        for _, v in pairs(data) do
          if v == "war_heg__huangquan" then return true end
        end
      end
    end,
    on_use = function(self, event, target, player, data)
      local room = player.room
      room:notifySkillInvoked(player, dianhu.name, "special")
      player:broadcastSkillInvoke(dianhu.name, 1)
      local targets = room:getOtherPlayers(player)
      local tos = room:askToChoosePlayers(player,{
        targets = targets,
        min_num = 1,
        max_num = 1,
        prompt = "#heg__dianhu-choose",
        skill_name = dianhu.name,
        cancelable = false,
      })
      if #tos == 0 then
        tos = table.random(targets, 1)
      end
      local to = tos[1]
      local mark = to:getTableMark("@@heg__dianhu")
      table.insert(mark, player.id)
      room:setPlayerMark(to, "@@heg__dianhu", mark)
    end,
})

dianhu:addEffect(fk.BuryVictim,{
    can_refresh = function(self, event, target, player, data)
      return not player.dead and type(player:getMark("@@heg__dianhu")) == "table"
    end,
    on_refresh = function(self, event, target, player, data)
      local mark = player:getMark("@@heg__dianhu")
      table.removeOne(mark, target.id)
      player.room:setPlayerMark(player, "@@heg__dianhu", #mark > 0 and mark or 0)
    end,
})

dianhu:addEffect(fk.Damaged,{
    is_delay_effect = true,
    can_trigger = function(self, event, target, player, data)
      if target and not (player.dead or target.dead) then
        local mark = target:getTableMark("@@heg__dianhu")
        if table.contains(mark, player.id) then
          return H.compareKingdomWith(data.from, player)
        end
      end
    end,
    on_use = function(self, event, target, player, data)
      local from = data.from
      player:broadcastSkillInvoke(dianhu.name, 2)
      if from and not from.dead then
        from:drawCards(1, dianhu.name)
      end
    end,
})

return dianhu